/**
 * 
 */
package com.interceptor;

import java.util.Map;

import com.action.SdkPayAction;
import com.action.UPayAction;
import com.auth.action.LoginAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author jun.huang
 * 
 */
public class AuthorizeInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	} 

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map<String, Object> session = invocation.getInvocationContext().getSession();
		Object action = (Action) invocation.getAction();
		if (action instanceof LoginAction
				|| action.getClass().toString().equals("class com.action.AbstractAction")
				|| action instanceof UPayAction
				|| action instanceof SdkPayAction) {
			return invocation.invoke();
		}
		if (session.get("account") == null) {
			return Action.LOGIN;
		} else {
			return invocation.invoke();
		}
	}

}
